from selenium.webdriver.common.by import By
from web_study.web_litemall_po.utils.log_utils import logger
from web_study.web_litemall_po.utils.web_utils import click_exception
from web_study.web_litemall_po.page_object.base_page import BasePage
from selenium.webdriver.support.wait import WebDriverWait


# 创建页面
class CategoryCreatePage(BasePage):

    __INPUT_CATEGORY = (By.CSS_SELECTOR, ".el-input__inner")
    __BTN_CONFIRM = (By.CSS_SELECTOR, ".dialog-footer>.el-button--primary")

    """创建类目页面：创建类目"""
    def create_category(self, category_name):
        logger.info("创建类目页面：创建类目")
        # 输入”类目名称“
        self.do_send_keys(category_name, self.__INPUT_CATEGORY)
        # self.driver.find_element(By.CSS_SELECTOR, ".el-input__inner").send_keys("新增电器测试")
        # 点击”确认“按钮
        WebDriverWait(self.driver, 5).until(click_exception(*self.__BTN_CONFIRM))
        # self.driver.find_element(By.CSS_SELECTOR, ".dialog-footer>.el-button--primary").click()
        # ==》类目列表页面
        from web_study.web_litemall_po.page_object.category_list_page import CategoryListPage
        return CategoryListPage(self.driver)